package com.sctvcloud.bazhong.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.bazhong.R;
import com.sctvcloud.bazhong.beans.NewsItem;
import com.sctvcloud.bazhong.ui.adapter.CommonFrgAdapter;
import com.sctvcloud.bazhong.ui.utils.GlideUtil;
import com.sctvcloud.bazhong.ui.utils.UIUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/6/23 0023.
 */

public class CommonFrgHolder extends BaseRecylerHolder<NewsItem> implements View.OnClickListener {
    @BindView(R.id.item_common_frg_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_common_frg_time)
    protected CustomFontTextView time;
    @BindView(R.id.item_common_frg_lable)
    protected CustomFontTextView lable;
    @BindView(R.id.item_common_frg_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_common_frg_type)
    protected ImageView news_type;
    @BindView(R.id.item_common_frg_play_length)
    protected CustomFontTextView play_length;
    @BindView(R.id.newes_detail_click_count)
    protected CustomFontTextView clickcount;
    private NewsItem mNewsItem;

    public CommonFrgHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(NewsItem newsItem) {
        mNewsItem = newsItem;
        title.setText(TextUtils.isEmpty(newsItem.getNewsTitle()) ? "" : newsItem.getNewsTitle());
        time.setText(TextUtils.isEmpty(newsItem.getPubTime()) ? "" : DateUtils.formatDate(DateUtils
                .getDataDate(newsItem),""));
        clickcount.setVisibility(View.VISIBLE);
        clickcount.setText(UIUtils.getReadingNumber(newsItem.getReadCount()));
        if (isAct) {
            if (newsItem.getNewsType() == 4) {
                lable.setText("专题");
            } else {
                lable.setText("四川观察");
            }
        } else {
            lable.setText(TextUtils.isEmpty(newsItem.getLable()) ? "" : newsItem.getLable());
        }

        if (newsItem.getNewsType() == 2) { //音频
            news_type.setImageResource(R.mipmap.icon_home_voice);
            news_type.setVisibility(View.VISIBLE);
        } else if (newsItem.getNewsType() == 3) {   //视频
            news_type.setImageResource(R.mipmap.icon_home_play);
            news_type.setVisibility(View.VISIBLE);
        } else {
            news_type.setVisibility(View.GONE);
        }
//        if (!TextUtils.isEmpty(newsItem.getNewsMediaLength())) {
//            play_length.setVisibility(View.VISIBLE);
//            play_length.setText(newsItem.getNewsMediaLength());
//        } else {
            play_length.setVisibility(View.GONE);
//        }
        if (!TextUtils.isEmpty(newsItem.getNewsImage())) {
            if (getType() == CommonFrgAdapter.VIEW_TYPE_LARGE) {
                GlideUtil.loadImgLarge169Def(context, newsItem.getNewsImage(), img);
            } else {
                GlideUtil.loadImgSmall169Def(context, newsItem.getNewsImage(), img);
                title.setLines(3);
            }
            img.setVisibility(View.VISIBLE);


        }else{
            img.setVisibility(View.GONE);
            title.setMaxLines(2);

        }
    }

    @Override
    public void onClick(View v) {
        if (internalClick != null) {
            itemView.setTag(R.id.adapter_item_data_key, mNewsItem);
            internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
        }
    }
}
